package com.ebupt.migu.fineoperationmedia.common;

import com.ebupt.migu.fineoperationmedia.entity.response.*;
import com.ebupt.migu.mediadata.pojo.*;

import java.util.stream.Collectors;

/**
 * @author liuyangyang@e-byte.com
 * @description: TODO
 * @date 2024/4/18 15:20
 */
public class JavaBeanConvertUtil {

    /**
     * 映射
     * 
     * @param media
     * @return
     */
    public static ResDataBean mediaRedisBeanConvertToResDataBean(MediaRedisBean media) {
        if (null == media) {
            return null;
        }
        ResDataBean data = new ResDataBean();
        data.setId(media.getActivityId());
        data.setName(media.getActivityName());
        if (null != media.getBlocks() && media.getBlocks().size() > 0) {
            data.setModule(1);
            data.setBlocks(media.getBlocks().stream().map(JavaBeanConvertUtil::convert_block)
                    .collect(Collectors.toList()));
        }
        if (null != media.getBanners() && media.getBanners().size() > 0) {
            data.setModule(2);
            data.setBanners(media.getBanners().stream().map(JavaBeanConvertUtil::convert_banner)
                    .collect(Collectors.toList()));
        }
        if (null != media.getKings() && media.getKings().size() > 0) {
            data.setModule(3);
            data.setKings(media.getKings().stream().map(JavaBeanConvertUtil::convert_king)
                    .collect(Collectors.toList()));
        }
        return data;
    }

    /**
     * block对象转换
     *
     * @param block
     * @return
     */
    public static ResBlockBean convert_block(BlockBean block) {
        ResBlockBean res = new ResBlockBean();
        res.setId(block.getBlockId());
        res.setName(block.getBlockName());
        if (null != block.getEntries() && block.getEntries().size() > 0) {
            res.setEntries(block.getEntries().stream().map(JavaBeanConvertUtil::convert_entry)
                    .collect(Collectors.toList()));
        }
        return res;
    }

    /**
     * entry对象转换
     *
     * @param entry
     * @return
     */
    public static ResEntryBean convert_entry(EntryBean entry) {
        ResEntryBean res = new ResEntryBean();
        res.setId(entry.getEntryId());
        res.setName(entry.getEntryName());
        res.setSkin(entry.getSkin() != 0);
        res.setImage1(entry.getImage1());
        res.setImage2(entry.getImage2());
        res.setLink(entry.getLink());
        return res;
    }

    /**
     * banner对象转换
     *
     * @param banner
     * @return
     */
    public static ResBannerBean convert_banner(BannerBean banner) {
        ResBannerBean res = new ResBannerBean();
        res.setId(banner.getBannerId());
        res.setImage(banner.getImage());
        res.setLink(banner.getLink());
        return res;
    }

    /**
     * king对象转换
     *
     * @param king
     * @return
     */
    public static ResKingBean convert_king(KingBean king) {
        ResKingBean res = new ResKingBean();
        res.setId(king.getEntryId());
        res.setName(king.getEntryName());
        res.setSkin(king.getSkin() != 0);
        res.setImage1(king.getImage1());
        res.setImage2(king.getImage2());
        res.setLink(king.getLink());
        return res;
    }
}
